﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<string>" %>
<select data-bind="options: availableProjects, 
                   optionsCaption:'Please select...',
                   optionsText: 'Value',
                   optionsValue: 'Id'
                   " class="validate[required] chz hide" id="vmProjectName" name="ProjectName" style="margin-bottom: 3px">
</select>             
<br/><br/>    
<a  class="icons icon-plus"></a>        
<%string ControllerName = Html.ViewContext.Controller.ValueProvider.GetValue("controller").RawValue.ToString();
  string linkpage = "Listings/ProjectDirectoryLocal/Step1";
  if (ControllerName == "PropertyInternational" || ControllerName == "ProjectInternational")
  {
      linkpage = "Listings/ProjectDirectoryInt/Step1";
  }
 %>
<a href="<%=Url.Content("~/") + linkpage%>" style="line-height: 5px;color: red"><b>Add Project Name</b></a>

<script type="text/javascript">
    $(document).ready(function() {
        //Begin Data
       var TypeProjectName = "INTERNATIONAL";
        <% if(ControllerName=="Property" || ControllerName=="Project" ){ %>
            TypeProjectName = "LOCAL";
       <%} %>
   
        var selected = "";
        <% if(Model.ToString()!=""){
         %>
            selected = <%=Model.ToString()%>;
         <%}  %>
        System.Data.ProjectNameModel = function() {
            var self = this;
            //
            self.availableProjects = ko.observableArray([]);
            self.selected = ko.observableArray([]);
            //save
            self.save = function(form) {
                alert("Ok");
            };
            self.loadProjectName = function() {
                $.getJSON(BASE_URL + "Listings/Ajax/getProjectname/"+TypeProjectName, function(result) {
                    self.availableProjects(result.Data);

                    $("#vmProjectName").chosen({
                        allow_single_deselect: true
                    });
                      if(selected !=""){
                           
                            $("#vmProjectName").val(selected).trigger("liszt:updated");
                        }
                    $("#vmProjectName").removeClass("hide");
                });

            };
           
        }
        
        //Fill Data
        var vmProjectName = new System.Data.ProjectNameModel();
        vmProjectName.loadProjectName();
        ko.applyBindings(vmProjectName, $("#vmProjectName")[0]);
          
    });

</script>

